package com.jike.noobmoney.mvp.view.fragment;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SearchView;
import android.util.Log;
import android.util.TypedValue;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.duoyou.ad.openapi.DyAdApi;
import com.jike.noobmoney.R;
import com.jike.noobmoney.adapter.TaskListAdapter;
import com.jike.noobmoney.adapter.jakewharton.salvage.RecyclingPagerAdapter;
import com.jike.noobmoney.contants.ConstantValue;
import com.jike.noobmoney.entity.BannerEntity;
import com.jike.noobmoney.entity.NewEntity;
import com.jike.noobmoney.entity.TaskListEntity;
import com.jike.noobmoney.mvp.presenter.TaskPresenter;
import com.jike.noobmoney.mvp.presenter.UserPresenter;
import com.jike.noobmoney.mvp.view.activity.ChallengeActivity;
import com.jike.noobmoney.mvp.view.activity.CheckInActivity;
import com.jike.noobmoney.mvp.view.activity.DianCaiActivity;
import com.jike.noobmoney.mvp.view.activity.GameCenterActivity;
import com.jike.noobmoney.mvp.view.activity.GameListActivity;
import com.jike.noobmoney.mvp.view.activity.HotTopActivity;
import com.jike.noobmoney.mvp.view.activity.MainActivity;
import com.jike.noobmoney.mvp.view.activity.MessageActivity;
import com.jike.noobmoney.mvp.view.activity.MyEventActivity;
import com.jike.noobmoney.mvp.view.activity.MyTaskActivity;
import com.jike.noobmoney.mvp.view.activity.NewListActivity;
import com.jike.noobmoney.mvp.view.activity.NewTaskActivity;
import com.jike.noobmoney.mvp.view.activity.NewTeachActivity;
import com.jike.noobmoney.mvp.view.activity.PushTaskActivity;
import com.jike.noobmoney.mvp.view.activity.QianDaoActivity;
import com.jike.noobmoney.mvp.view.activity.RankActivity;
import com.jike.noobmoney.mvp.view.activity.SearchTastListActivity;
import com.jike.noobmoney.mvp.view.activity.SearchTastListActivityNew;
import com.jike.noobmoney.mvp.view.activity.TaskDetailActivity;
import com.jike.noobmoney.mvp.view.activity.TastListActivity;
import com.jike.noobmoney.mvp.view.widget.AutoScrollViewPager;
import com.jike.noobmoney.mvp.view.widget.MarqueeTextView;
import com.jike.noobmoney.mvp.view.widget.MarqueeTextViewClickListener;
import com.jike.noobmoney.mvp.view.widget.indicator.CirclePageIndicator;
import com.jike.noobmoney.net.IView;
import com.jike.noobmoney.pcegg.PcEggActivity;
import com.jike.noobmoney.util.ComUtils;
import com.jike.noobmoney.util.ImageShowUtil;
import com.jike.noobmoney.util.ListUtils;
import com.jike.noobmoney.util.SPUtils;
import com.jike.noobmoney.util.ToastUtils;
import com.jike.noobmoney.xq.XqActivity;
import com.lz.playmy.WowanIndex;
import com.mdad.sdk.mduisdk.AdManager;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.toomee.mengplus.manager.TooMeeManager;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

import static android.app.Activity.RESULT_OK;

/**
 * Created by kekex on 2018/8/21.
 * 游戏任务
 */
public class IndexFragment extends BaseFragment implements View.OnClickListener, IView {

    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R.id.refreshLayout)
    SmartRefreshLayout refreshLayout;
    Unbinder unbinder;
    private TaskListAdapter adapter;
    private List<TaskListEntity.TaskBean> mData = new ArrayList<>();
    private List<BannerEntity.HomeBean> mBannerData = new ArrayList<>();
    private List<String> images = new ArrayList<>();
    private TaskPresenter taskPresenter;
    private ImagePagerAdapter imageAdatper;
    private boolean isRefresh = true;
    private int page = 1;
    private UserPresenter userPresenter;
    private String userid = "";
    private View headerView;
    private AutoScrollViewPager index_auto_scroll_view;
    private CirclePageIndicator cpi_indicator;
    private TabLayout tabLayout;
    private LinearLayout ll_xs,ll_yx,ll_rm,ll_qd,ll_jc,ll_ph,ll_kf;
    private LinearLayout ll_money,ll_xyx;
    private LinearLayout ll_rw,ll_tz;
    private LinearLayout ll_wx;
    private LinearLayout ll_xw;
    public SearchView searchView;

    @Override
    public void onResume() {
        super.onResume();
        getRedrot();
        searchView.setFocusable(true);
        searchView.setFocusableInTouchMode(true);
//mSearchView.requestFocus();  //获取焦点
     //   loadData(true,position);
    }

    @Override
    protected int layoutResID() {
        return R.layout.index_fragment;
    }

    @Override
    protected void initData() {
        taskPresenter = new TaskPresenter(this);
        userPresenter = new UserPresenter(this);
        userid = SPUtils.getInstance().getString(ConstantValue.SpType.userid);
        initView();
        initListener();
        loadData(true,position);
        getNewList();
    }

    private void getRedrot() {
        if (userPresenter != null) {
            userPresenter.getRedrot(userid, ConstantValue.RequestKey.message_num);
        }
    }
    public void getNewList()
    {
        if (userPresenter != null) {
            taskPresenter.getNewlist(userid, "" + 1, "10", ConstantValue.RequestKey.newlist);
        }
    }


//    private void setRedrot(String num) {
//        if (TextUtils.isEmpty(num) || "0".equals(num)) {
//            tvCorner.setVisibility(View.GONE);
//        } else {
//            tvCorner.setVisibility(View.VISIBLE);
//            tvCorner.setText(num);
//        }
//    }
    public int position;
    private MarqueeTextView marqueeTv;


    private void initView() {
        headerView = LayoutInflater.from(context).inflate(R.layout.layout_head_update, null, false);

        index_auto_scroll_view  = (AutoScrollViewPager)headerView.findViewById(R.id.index_auto_scroll_view);
        cpi_indicator				= (CirclePageIndicator)headerView.findViewById(R.id.cpi_indicator);

        ll_xs=(LinearLayout)headerView.findViewById(R.id.ll_xs);
        ll_xs.setOnClickListener(this);
        ll_yx=(LinearLayout)headerView.findViewById(R.id.ll_yx);
        ll_yx.setOnClickListener(this);
        ll_rm=(LinearLayout)headerView.findViewById(R.id.ll_rm);
        ll_rm.setOnClickListener(this);
        ll_qd=(LinearLayout)headerView.findViewById(R.id.ll_qd);
        ll_qd.setOnClickListener(this);
        ll_money=(LinearLayout)headerView.findViewById(R.id.ll_money);
        ll_money.setOnClickListener(this);

        ll_xyx=(LinearLayout)headerView.findViewById(R.id.ll_xyx);
        ll_xyx.setOnClickListener(this);

        marqueeTv = (MarqueeTextView)headerView.findViewById(R.id.marqueeTv);


        ll_wx=(LinearLayout)headerView.findViewById(R.id.ll_wx);
        ll_wx.setOnClickListener(this);

        TextView   et_search=(TextView)headerView.findViewById(R.id.et_search);
        et_search.setOnClickListener(this);
        searchView=(SearchView) headerView.findViewById(R.id.searchView);
        searchView.setIconified(false);
        searchView.onActionViewExpanded();
        // 设置搜索文本监听
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            //当点击搜索按钮时触发该方法
            @Override
            public boolean onQueryTextSubmit(String query) {
                Log.e("","=====query="+query);
                    String value=query.toString();
                    startActivity(new Intent(getActivity(),SearchTastListActivityNew.class).putExtra("key",query));
                    searchView.clearFocus();
                return false;
            }

            //当搜索内容改变时触发该方法
            @Override
            public boolean onQueryTextChange(String newText) {
                Log.e("","=====newText="+newText);
                return false;
            }
        });
        TextView txt_search = searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
//设置字体大小为14sp
        txt_search.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);//14sp
////设置字体颜色
//        txt_search.setTextColor(getResources().getColor(R.color.notice_color));
////设置提示文字颜色
//        txt_search.setHintTextColor(getResources().getColor(R.color.hint_color));
//        //去掉searchview下划线
        View view_line = searchView.findViewById(android.support.v7.appcompat.R.id.search_plate);
        view_line.setBackgroundColor(Color.TRANSPARENT);
        searchView.setQueryHint("请输入搜索关键字");//设置查询提示字符串
        searchView.clearFocus();

        ll_jc=(LinearLayout)headerView.findViewById(R.id.ll_jc);
        ll_jc.setOnClickListener(this);

        ll_ph=(LinearLayout)headerView.findViewById(R.id.ll_ph);
        ll_ph.setOnClickListener(this);
        ll_xw=(LinearLayout)headerView.findViewById(R.id.ll_xw);
        ll_xw.setOnClickListener(this);

        ll_rw=(LinearLayout)headerView.findViewById(R.id.ll_rw);
        ll_rw.setOnClickListener(this);

        ll_tz=(LinearLayout)headerView.findViewById(R.id.ll_tz);
        ll_tz.setOnClickListener(this);

        tabLayout=(TabLayout) headerView.findViewById(R.id.tb_top);
        tabLayout.addTab(tabLayout.newTab().setText("置顶悬赏"),0);
        tabLayout.addTab(tabLayout.newTab().setText("最新悬赏"),1);
        tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                position=tab.getPosition();
                loadData(true,position);
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });


        imageAdatper=new ImagePagerAdapter(context, mBannerData);
        index_auto_scroll_view.setAdapter(imageAdatper);
        cpi_indicator.setViewPager(index_auto_scroll_view);
        index_auto_scroll_view.startAutoScroll();
        index_auto_scroll_view.setInterval(4000);
        index_auto_scroll_view.setSlideBorderMode(AutoScrollViewPager.SLIDE_BORDER_MODE_TO_PARENT);

//        banner.setBannerPageClickListener((view, position) -> {
//            if (mBannerData != null && mBannerData.size() > 0) {
//                BannerEntity.HomeBean homeBean = mBannerData.get(position);
//                String url = homeBean.getUrl();
//                if ("0".equals(url)) {
//                    //聚享玩
//                    TooMeeManager.start(context);
//                } else if ("1".equals(url)) {
//                    //蛋蛋赚
//                    Intent intent = new Intent();
//                    intent.setClass(context.getApplicationContext(), WowanIndex.class);
//                    startActivity(intent);
//                } else if ("2".equals(url)) {
//                    //邀请好友
//                    MainActivity activity = (MainActivity) getActivity();
//                    if (activity != null) {
//                        activity.goRecommend(3);
//                    }
//                } else if ("3".equals(url)) {
//                    //进qq群
//                    ComUtils.startQQ(context, 3, "564104407");
//                } else if ("4".equals(url)) {
//                    //官方推荐
//                    startActivity(new Intent(context, HotTopActivity.class));
//                } else if (url.startsWith("http")) {
//                    //跳转网页
//                    if (url.contains("userid=")) {
//                        String userid = SPUtils.getInstance().getString(ConstantValue.SpType.userid);
//                        url = url + userid;
//                    }
//                    Intent intent = new Intent(context, MyEventActivity.class);
//                    intent.putExtra(MyEventActivity.BUNDLE_KEY_URL, url);
//                    startActivity(intent);
//                }
//            }
//        });

        adapter = new TaskListAdapter(context);
        recyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
        recyclerView.setAdapter(adapter);
        adapter.setHeaderView(headerView);
    }

    private void initListener() {
        adapter.setOnItemClickListener((adapterView, view, position, l) -> {
            if (position == 0) {
                return;
            }
            TaskListEntity.TaskBean item = (TaskListEntity.TaskBean) adapter.getItem(position);

            Intent intent = new Intent(context, TaskDetailActivity.class);
            intent.putExtra(TaskDetailActivity.t_id, "" + item.getT_id());
            startActivity(intent);
        });

        refreshLayout.setOnRefreshListener(refreshlayout -> loadData(true,position));

        refreshLayout.setOnLoadMoreListener(refreshLayout -> loadData(false,position));
    }

    private void loadData(boolean isRefresh,int positon) {
        showProgressDialog();

        this.isRefresh = isRefresh;
        if (isRefresh) {
            page = 1;
        } else {
            page++;
        }

        if (taskPresenter != null) {
            taskPresenter.getBanner(ConstantValue.RequestKey.banner);
            if(positon==0) {
                taskPresenter.getJinRiList(userid, "0", "" + page, "10", ConstantValue.RequestKey.task_jinri_list);
            }else if(positon==1)
            {
                taskPresenter.getGuanfangList(userid,""+page, "10", ConstantValue.RequestKey.task_jinri_list);
            }
        }
    }

    private void disLoad() {
        if (refreshLayout != null) {
            refreshLayout.finishRefresh();
            refreshLayout.finishLoadMore();
        }
        dismissProgressDialog();
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.cardview_yaoqing:
                //邀请
                MainActivity activity = (MainActivity) getActivity();
                if (activity != null) {
                    activity.goRecommend(3);
                }
                break;
            case R.id.et_search:
                startActivity(new Intent(context, SearchTastListActivityNew.class));
                break;

            case R.id.ll_xyx:
                //ToastUtils.showShortToast("该功能尚未开放，敬请期待");
                startActivity(new Intent(context, GameListActivity.class));
                break;



            case R.id.ll_wx:
                AdManager.getInstance(getActivity()).setBackGroundColor("#FFE148"); //标题栏背景色
                AdManager.getInstance(getActivity()).setWeChatTaskTitle("微信赚钱");//小程序标题
                AdManager.getInstance(getActivity()).openWeChatTaskSetList(getActivity());
                break;

            case R.id.ll_xw:
              ToastUtils.showShortToast("该功能尚未开放，敬请期待！");
                break;


            case R.id.btn_kuaisu:
                //快速任务
                Intent intent = new Intent();
                intent.setClass(context, WowanIndex.class);
                startActivity(intent);
                break;
            case R.id.cardview_gaoe:
                //高额任务
                TooMeeManager.start(context);
                break;
            case R.id.cardview_xingyun:
                //幸运
                String url = "http://engine.liulianqc.com/index/activity?appKey=ZgzfvSPbz5aG1JE1qsTrCeXWXyd&adslotId=485";
                startActivity(new Intent(context, MyEventActivity.class).putExtra(MyEventActivity.BUNDLE_KEY_URL, url));
                break;
            case R.id.cardview_qq:
                //QQ群
                ComUtils.startQQ(context, 3, "564104407");
                break;

            //-------------------------------2.0-----------------------------------
            case R.id.ll_check_in:
                //每日签到
                startActivityForResult(new Intent(context, QianDaoActivity.class), 200);
                //startActivity(new Intent(context, QianDaoActivity.class));
                break;
            case R.id.ll_fast_task:
                //快速任务 高额任务->简单任务  蛋蛋赚

//                String utoken = SPUtils.getInstance().getString(ConstantValue.SpType.utoken);
//                String imie = SPUtils.getInstance().getString(ConstantValue.SpType.imie);
//                if (TextUtils.isEmpty(utoken)) {
//                    ToastUtils.showShortToastSafe("用户获取失败");
//                }
//                String jxw = "http://task.juxiangwan.com/reward?utoken=" + utoken + "&mid=197&device_code=" + imie + "&sw=false";
//                Intent intent2 = new Intent(context, MyEventTwoActivity.class);
//                intent2.putExtra(MyEventTwoActivity.BUNDLE_KEY_URL, jxw);
//                intent2.putExtra(MyEventTwoActivity.BUNDLE_KEY_TITLE, "简单任务");
//                startActivity(intent2);

                DyAdApi.getDyAdApi().jumpAdList(context, userid, 0);
                DyAdApi.getDyAdApi().setTitleBarColor(R.color.maincolor);
                DyAdApi.getDyAdApi().setTitle(getString(R.string.app_name));
                break;
            case R.id.ll_shiwan:
                //游戏试玩 高额悬赏->试玩赚钱   聚享玩
                //Intent intent2 = new Intent();
                //intent2.setClass(context, WowanIndex.class);
                //startActivity(intent2);

                TooMeeManager.start(context);
                break;
            case R.id.ll_invite_friends:
                //邀请好友
//                MainActivity activity2 = (MainActivity) getActivity();
//                if (activity2 != null) {
//                    activity2.goRecommend(3);
//                }
                //配置落地页TitleBar的背景颜色和文字颜色
//                YmConfig.setTitleBarColors(0xfff8c45f, 0xffffffff);
//                YmConfig.openReader();
                startActivity(new Intent(context, DianCaiActivity.class));
                break;
            case R.id.ll_push_task:
                //发布任务
                startActivity(new Intent(context, PushTaskActivity.class));
                break;
            case R.id.ll_my_push:
                //我的任务
                startActivity(new Intent(context, MyTaskActivity.class));
                break;
            case R.id.iv_home_invite:
                //新手任务
                startActivityForResult(new Intent(context, NewTaskActivity.class), 200);
                break;
            case R.id.iv_home_gaoe:
                //官方推荐
                startActivity(new Intent(context, HotTopActivity.class));
                break;
            case R.id.iv_message:
                //消息
                startActivity(new Intent(context, MessageActivity.class));
                break;
            case R.id.iv_game1:
                //pc蛋蛋
                PcEggActivity.startActivity(context, "", userid);
                break;
            case R.id.iv_game2:
                //嘻趣
                XqActivity.startActivity(context, "3251", "wsfhnb1v8sxbzq71", userid);
                break;
            case R.id.ll_ph:
                //周排行
                //排行榜
//                MainActivity activity1 = (MainActivity) getActivity();
//                if (activity1 != null) {
//                    activity1.goRecommend(1);
//                }
                startActivity(new Intent(context, RankActivity.class));
                break;
            case R.id.ll_jc:
                //新手教程
                startActivity(new Intent(context,NewTeachActivity.class));
                break;
            case R.id.ll_money:
                //新手红包
                //新手任务
                startActivityForResult(new Intent(context, NewTaskActivity.class), 200);
                break;
            case R.id.ll_qd:
                //每日签到
                startActivityForResult(new Intent(context, CheckInActivity.class), 200);
                break;
            case R.id.ll_rm:
                //热门悬赏
                startActivity(new Intent(context, HotTopActivity.class));
                break;
            case R.id.ll_yx:
                //游戏大厅
                startActivity(new Intent(context, GameCenterActivity.class));
                break;
            case R.id.ll_xs:
                //悬赏大厅
                startActivity(new Intent(context, TastListActivity.class));
                break;
            case R.id.ll_tz:
                //每日挑战
                startActivity(new Intent(context, ChallengeActivity.class));
                break;
            case R.id.ll_rw:
                //我的任务
                startActivity(new Intent(context, MyTaskActivity.class));
                break;
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 200 && resultCode == RESULT_OK) {
            MainActivity activity2 = (MainActivity) getActivity();
            if (activity2 != null) {
                //任务大厅
                //activity2.goRecommend(2);
            }
        }
    }

    @Override
    public void onStart() {
        super.onStart();
        //开始轮播
//        if (banner != null) {
//            banner.start();
//        }
    }

    @Override
    public void onStop() {
        super.onStop();
        //结束轮播

//        if (banner != null) {
//            banner.pause();
//        }
    }
    public class ImagePagerAdapter extends RecyclingPagerAdapter {

        private Context context;
        private List<BannerEntity.HomeBean> imageIdList;
        private LayoutInflater inflater;
        private int           size;
        private boolean       isInfiniteLoop;
        public ImagePagerAdapter(Context context, List<BannerEntity.HomeBean> imageIdList) {
            this.context = context;
            this.imageIdList = imageIdList;
            this.size = ListUtils.getSize(imageIdList);
            isInfiniteLoop = false;
            inflater=LayoutInflater.from(context);
        }

        @Override
        public int getCount() {
            // Infinite loop
            return isInfiniteLoop ? Integer.MAX_VALUE : ListUtils.getSize(imageIdList);
        }
        /**
         * get really position
         *
         * @param position
         * @return
         */
        private int getPosition(int position) {
            return isInfiniteLoop ? position % size : position;
        }

        @Override
        public View getView(int position, View view, ViewGroup container) {
            ViewHolder holder;
            if (view == null) {
                view=inflater.inflate(
                        R.layout.index_image_list_item, null);
                holder = new ViewHolder();
                holder.imageView=(ImageView) view.findViewById(R.id.image_item);
                view.setTag(holder);
            } else {
                holder = (ViewHolder)view.getTag();
            }
            holder.imageView.setScaleType(ImageView.ScaleType.FIT_XY);
            BannerEntity.HomeBean model=imageIdList.get(position);
            ImageShowUtil.showImage(model.getPicture(),holder.imageView);
            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
//                    Intent intent =new Intent(context,WebActivity.class);
//                    intent.putExtra("url",model.newsurl);
//                    intent.putExtra("title","公告");
//                    context.startActivity(intent);
                    String url=model.getUrl();
                    switch (url)
                    {
                        case "1":
//                            String urlStr=model.getText();
//                            Intent intent = new Intent(context, MyEventActivity.class);
//                            intent.putExtra(MyEventActivity.BUNDLE_KEY_URL, model.text);
//                            startActivity(intent);

                            Intent intent= new Intent();
                            intent.setAction("android.intent.action.VIEW");
                            Uri content_url = Uri.parse(model.text);
                            intent.setData(content_url);
                            context.startActivity(intent);
                            break;
                        case "2":
                            //悬赏大厅
                            startActivity(new Intent(context, TastListActivity.class));
                            break;
                        case "3":
                        //游戏大厅
                        startActivity(new Intent(context, GameCenterActivity.class));
                        break;
                        case "5":
                            //邀请页面
                            MainActivity activity1 = (MainActivity) getActivity();
                            if (activity1 != null) {
                                activity1.goRecommend(2);
                            }
                            break;

                        case "6":

                            //热门悬赏
                            startActivity(new Intent(context, HotTopActivity.class));
                            break;
                        case "7":

                            //微信悬赏
                            AdManager.getInstance(getActivity()).setBackGroundColor("#FFE148"); //标题栏背景色
                            AdManager.getInstance(getActivity()).setWeChatTaskTitle("微信赚钱");//小程序标题
                            AdManager.getInstance(getActivity()).openWeChatTaskSetList(getActivity());
                            break;
                        case "8":

                            //小游戏赚
                            startActivity(new Intent(context, GameListActivity.class));
                            break;
                        case "9":

                            //新人红包
                            startActivityForResult(new Intent(context, NewTaskActivity.class), 200);
                            break;

                        case "10":

                            //每日签到
                            startActivity(new Intent(context, CheckInActivity.class));
                            break;
                        case "11":

                            //新闻赚钱
                            //startActivity(new Intent(context, CheckInActivity.class));
                            break;
                        case "12":

                            //每日挑战
                            startActivity(new Intent(context, ChallengeActivity.class));
                            break;

                        case "4":
                            //QQ群
                            ComUtils.startQQ(context, 3, model.text);
                            break;
                    }


                }
            });

            return view;
        }

        private  class ViewHolder {

            ImageView imageView;
        }

        /**
         * @return the isInfiniteLoop
         */
        public boolean isInfiniteLoop() {
            return isInfiniteLoop;
        }

        /**
         * @param isInfiniteLoop the isInfiniteLoop to set
         */
        public ImagePagerAdapter setInfiniteLoop(boolean isInfiniteLoop) {
            this.isInfiniteLoop = isInfiniteLoop;
            return this;
        }
    }

    @Override
    public void onSuccess(String code, String msg, Object data, String actionType) {
        if (ConstantValue.RequestKey.banner.equals(actionType)) {
            List<BannerEntity.HomeBean> data1 = (List<BannerEntity.HomeBean>) data;
            if (data1 != null && data1.size() > 0) {
                mBannerData.clear();
                mBannerData.addAll(data1);
                imageAdatper.notifyDataSetChanged();
            }
            //setBanner(mBannerData);

        }


        if (ConstantValue.RequestKey.newlist.equals(actionType)) {
            List<NewEntity.MessageBean> task = (List<NewEntity.MessageBean>) data;

            String [] strArray = new String [task.size()];
            if (task != null && task.size() > 0) {
                    for(int i=0;i<task.size();i++)
                    {
                        String str=task.get(i).getTitle();
                        strArray[i]=str;
                        //strArray[i]=str.substring(0,str.length()>=15?15:str.length());
                    }
                marqueeTv.setTextArraysAndClickListener(strArray, new MarqueeTextViewClickListener() {
                    @Override
                    public void onClick(View view) {
                        //startActivity(new Intent(MainActivity.this,AnotherActivity.class));
                        startActivity(new Intent(context, NewListActivity.class));
                    }
                });
            }

        }

        if (ConstantValue.RequestKey.task_jinri_list.equals(actionType)) {
            List<TaskListEntity.TaskBean> task = (List<TaskListEntity.TaskBean>) data;
            if (task != null && task.size() > 0) {
                if (isRefresh) {
                    mData.clear();
                    mData.addAll(task);
                } else {
                    mData.addAll(task);
                }
            }else{
                ToastUtils.showLongToast("没有更多数据了");
            }

            adapter.refresh(mData);
        }

        if (ConstantValue.RequestKey.message_num.equals(actionType)) {
            String number = (String) data;
           // setRedrot(number);
        }

        disLoad();
    }

//    private void setBanner(List<BannerEntity.HomeBean> data) {
//        images.clear();
//        if (data.size() > 0) {
//            banner.setVisibility(View.VISIBLE);
//            final List<String> images = new ArrayList<>();
//            for (int i = 0; i < data.size(); i++) {
//                images.add(ConstantValue.IMG_BASEURL + data.get(i).getPicture());
//            }
//            BannerHolderCreator bannerHolderCreator = new BannerHolderCreator();
//            banner.setPages(images, bannerHolderCreator);
//
//            //切换时间间隔
//            banner.setDelayedTime(5000);
//            banner.setDuration(2000);
//            banner.start();
//        } else {
//            banner.setVisibility(View.GONE);
//        }
//    }

    @Override
    public void onFailed(String code, String msg) {
        disLoad();
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
